﻿<%@ Page Language="C#" MasterPageFile="~/Manager.master" AutoEventWireup="true" CodeFile="OrderDetail.aspx.cs"
    Inherits="Manager_OrderDetail_OrderDetail" %>

<%@ Register Src="../../Pub/Module/Calendar.ascx" TagName="Calendar" TagPrefix="uc1" %>

<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <link href="../../Pub/Css/ExportStyles.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" language="javascript">
      function Picker1_onSelectionChanged(sender, eventArgs)
      {
        cldStart.SetSelectedDate(Picker1.GetSelectedDate());   
        cldStart.Show();
      }
      function cldStart_onSelectionChanged(sender, eventArgs)
      {
      
            var fromDate = cldStart.GetSelectedDate();
            var toDate = cldEnd.GetSelectedDate();
            Picker1.SetSelectedDate(fromDate);            
           /* if(fromDate > toDate)
            {
              Picker2.SetSelectedDate(fromDate);
              cldEnd.SetSelectedDate(fromDate);
            }  */             
      }
      
      function Picker2_onSelectionChanged(sender, eventArgs)
      {
        cldEnd.SetSelectedDate(Picker2.GetSelectedDate());
        cldEnd.Show();
      }
      function cldEnd_onSelectionChanged(sender, eventArgs)
      {         
            var fromDate = cldStart.GetSelectedDate();
            var toDate = cldEnd.GetSelectedDate();
            Picker2.SetSelectedDate(toDate);            
           /* if(fromDate > toDate)
            {
              Picker1.SetSelectedDate(toDate);
              cldStart.SetSelectedDate(toDate);
            }         */           
      }
    //]]>
    </script>

    <table border="0" -="0" cellspacing="0" style="width: 100%">
        <tr>
            <td nowrap="nowrap" style="height: 3px">
                <table border="1" cellpadding="2" cellspacing="0" style="width: 100%; border-collapse: collapse"
                    bordercolor="#407db3" bgcolor="#f7ffe4">
                    <tr>
                        <td align="center" nowrap="nowrap">
                            <asp:Button ID="btnSearch" runat="server" CssClass="cssButton" Text="Tìm kiếm" Width="81px"
                                OnClick="btnSearch_Click" /></td>
                        <td nowrap="nowrap" class="td_Title">
                            <asp:Label ID="Label5" runat="server" Text="Ngày đặt hàng:"></asp:Label>
                            &nbsp;
                        </td>
                        <td nowrap="nowrap">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td>
                                        </td>
                                        <td align="center">
                                            <uc1:Calendar ID="Calendar1" runat="server" />
                                            &nbsp;</td>
                                        <td align="center" style="width: 2px" valign="middle">
                                            &nbsp;~&nbsp;</td>
                                        <td align="center" valign="top">
                                            &nbsp;<uc1:Calendar ID="Calendar2" runat="server" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td class="td_Title" colspan="1" nowrap="nowrap">
                            <asp:Label ID="Label1" runat="server" Text="Đơn đặt hàng:"></asp:Label></td>
                        <td colspan="1" nowrap="nowrap">
                            <asp:TextBox ID="txtDDH" runat="server" CssClass="txt_Product" Width="150px"></asp:TextBox></td>
                        <td colspan="1" nowrap="nowrap">
                        </td>
                    </tr>
                    <tr>
                        <td id="Td1" runat="server" align="center" nowrap="nowrap">
                            <input id="Button1" class="cssButton" type="button" runat="server" value="Quay lại"
                                onclick="javascript:history.go(-1)" style="width: 81px" /></td>
                        <td nowrap="nowrap" class="td_Title">
                            <asp:Label ID="Label2" runat="server" Text="Tên khách hàng:"></asp:Label></td>
                        <td nowrap="nowrap">
                            <asp:TextBox ID="txtCusNm" runat="server" CssClass="txt_Product" Width="90%"></asp:TextBox></td>
                        <td nowrap="nowrap" class="td_Title">
                            <asp:Label ID="Label4" runat="server" Text="Trạng thái:"></asp:Label></td>
                        <td nowrap="nowrap">
                            <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlState_SelectedIndexChanged" Enabled="false">
                                <asp:ListItem Value="">Tất cả</asp:ListItem>
                                <asp:ListItem Value="N">Chờ x&#225;c nhận</asp:ListItem>
                                <asp:ListItem Value="Y">Đ&#227; x&#225;c nhận</asp:ListItem>
                                <asp:ListItem Value="S">Đang giao h&#224;ng</asp:ListItem>
                                <asp:ListItem Value="E">Đ&#227; giao h&#224;ng</asp:ListItem>
                                <asp:ListItem Value="C">Hủy bỏ</asp:ListItem>
                            </asp:DropDownList>&nbsp;
                        </td>
                        <td nowrap="nowrap" align="center">
                            <asp:ImageButton ID="imgExportExcel" runat="server" ImageUrl="../../Images/Icon/icon_excel.gif"
                                ToolTip="Export to Excel" OnClick="imgExportExcel_Click" Visible="false" /></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align="right" style="height: 2px">
            </td>
        </tr>
        <tr>
            <td colspan="1" nowrap="nowrap">
                <asp:GridView ID="grvMaster" runat="server" AutoGenerateColumns="False" CellPadding="2"
                    BorderWidth="1px" Width="100%" OnRowDataBound="grvMaster_RowDataBound" DataKeyNames="OrderID"
                    BorderColor="#407db3" AllowPaging="True" OnPageIndexChanging="grvMaster_PageIndexChanging"
                    PageSize="20">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                            </HeaderTemplate>
                            <ItemTemplate>
                            </ItemTemplate>
                            <ItemStyle CssClass="cssBorderGrv" Width="1%" HorizontalAlign="Center" />
                            <HeaderStyle CssClass="cssBorderGrv" Width="1%" />
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                Mã đơn hàng</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="hplOrderID" runat="server" Text='<%# Eval("OrderID") %>' Font-Bold="true"
                                    ForeColor="green"></asp:Label>
                            </ItemTemplate>
                            <ItemStyle Wrap="False" Width="1%" HorizontalAlign="Center" CssClass="cssBorderGrv" />
                            <HeaderStyle CssClass="cssBorderGrv" Wrap="False" />
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                T&#234;n Kh&#225;ch H&#224;ng</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="hplHoten" runat="server" Text='<%# Eval("CusNm") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle CssClass="cssBorderGrv" Wrap="False" />
                            <HeaderStyle CssClass="cssBorderGrv" Width="25%" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="Quantity" HeaderText="Số lượng">
                            <ItemStyle HorizontalAlign="Right" CssClass="cssBorderGrv" />
                            <HeaderStyle CssClass="cssBorderGrv" Width="3%" Wrap="False" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Total" HeaderText="Th&#224;nh tiền (VNĐ)" DataFormatString="{0:###,###,##0}">
                            <ItemStyle HorizontalAlign="Right" CssClass="cssBorderGrv" Wrap="False" />
                            <HeaderStyle CssClass="cssBorderGrv" Wrap="False" Width="5%" />
                        </asp:BoundField>
                        <asp:BoundField DataField="Note_MK"  HeaderText="Loại đơn">
                            <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Center" Wrap="False" />
                            <HeaderStyle CssClass="cssBorderGrv" Width="1%" Wrap="False" />
                        </asp:BoundField>                        
                        <asp:TemplateField>
                            <HeaderTemplate>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <img id="imgSave" runat="server" width="17" height="17"  class="ShowHist" State='close' OrderID='<%# Eval("OrderID") %>'/>
                            </ItemTemplate>
                            <ItemStyle CssClass="cssBorderGrv" Width="3%" HorizontalAlign="Center" />
                            <HeaderStyle CssClass="cssBorderGrv" />
                        </asp:TemplateField>
                    </Columns>
                    <RowStyle CssClass="gvRowStyle" Height="10px" />
                    <FooterStyle CssClass="gv_FooterBasket" BackColor="paleturquoise" />
                    <HeaderStyle CssClass="cssHeader" Height="20px" HorizontalAlign="Center" Wrap="False" />
                    <AlternatingRowStyle CssClass="gvAlternatingRowStyle" Height="10px" />
                    <EmptyDataTemplate>
                        <asp:Label ID="lblEmpty" runat="server" Text="Chưa có đơn đặt hàng"></asp:Label>
                    </EmptyDataTemplate>
                    <EmptyDataRowStyle Font-Size="13px" ForeColor="Red" Font-Names="Tahoma" />
                </asp:GridView>
            </td>
        </tr>
        <tr>
            <td nowrap="nowrap">
                &nbsp;</td>
        </tr>
    </table>
    &nbsp;
    <input type="hidden" id="hPrint" runat="server" value="0" />
    <script language="javascript" type="text/javascript">
      var Url='<%= ResolveClientUrl("~/")%>';
     //*************************************************
      $('.ShowHist').live('click', function()
       {            
           
                  var OrderID=$(this).attr("OrderID");                   
                  var tdNewRow=$(this).closest('tr').next().find("td");       
                 
                  if(StateNewRow($(this),tdNewRow))
                  {           
                      $.ajax({ 
                                   type: "GET", 
                                   url: Url+ "Pub/Ajax/AjaxQueryAdmin.aspx?type=getfloworderhist&OrderID="+OrderID, 
                                   success: function(resp)
                                   { 
                                         tdNewRow.html(resp)     ;         
                                   } 
                                   ,  error:function (xhr, ajaxOptions, thrownError){
                                            alert("Error");
                                 }    
                     });         
                  } 
                
            
                  
                            
       }); 
      
     function StateNewRow(obj,cell)  
     {
           var state=obj.attr("State");          
           if(state=="close")     
           {   
                 obj.closest('tr').next().show();
                 obj.attr("State","open") ; 
                 cell.html("Loadding...") ;
                 return true; 
           } 
           else
           {
                obj.closest('tr').next().hide();
                obj.attr("State","close") ;                
           }      
           return false;  
     }
   //*************************************************
    
    
    
    function fnCheckAll(obj)
    {
        var grvMaster=document.getElementById("<%= grvMaster.ClientID %>");
        var flag=false;
        if(obj.checked==true)
        {   
            flag=true;        
        }
         for(var i=0;i<grvMaster.rows.length;i++)
         {           
             try
             {
                grvMaster.rows[i].cells[0].children[0].checked=flag;
               }catch(e) {};               
          }  
    }
    
    function ProcessOrder(sState)
    {
        var sOrderID='<%=Request["sOrderID"]%>'
        Manager_OrderDetail_OrderDetailOK.AjaxUpdateOrderState(sState,sOrderID,CallBackClient)
    }
    function CallBackClient(res)
    {
        if(res!=null)
        {
            var myMsg=res.value;
            if(myMsg!=null)
            {
                if(myMsg=="Y")
                {
                     alert('Đã duyệt thành công');
                } 
                else if(myMsg=="N")
                {
                     alert('Hủy bỏ thành công');
                }               
            }          
           
        }
        else
        {
            alert('Error !!!')
        }
        
    }
    
    //Neu co tham so cho in Trang

    try{
            var IsPrint='<%=Request["IsPrint"]%>';
           var CodeID='<%=Request["CodeID"]%>';
          var sOrderID='<%=Request["sOrderID"]%>';  
            var hPrint=document.getElementById("<%= hPrint.ClientID %>")
            if(IsPrint=="S" && hPrint.value=="0") 
            {
                 fnPrintOrder(CodeID,sOrderID,"S");
                 hPrint.value="1";
            }  
    }
    catch(e){}
    
    function fnPrintOrder(CodeID,OrderID,State)
    {
        var width=screen.availWidth-30;
        var height=screen.availHeight-20;
        var left = parseInt((screen.availWidth/2) - (width/2));
		var top = parseInt((screen.availHeight/2) - (height/2));
        //var feature="width="+width+",height="+height+",menu=0,scrollbars=1,status=1,location=0,resizable=1,left=" + left + ",top=20,screenX=" + left + ",screenY=" + top;
        var feature="menu=0,scrollbars=1,status=1,location=0,resizable=1,fullscreen=1";
       if(OrderID.startsWith("HD"))
       {
            window.open("OrderDetailFilmOK.aspx?CodeID=" + CodeID  + "&sOrderID=" +OrderID+ "&sState=" + State,"",feature)
       }
       else
       {
            window.open("OrderDetailOK.aspx?CodeID=" + CodeID  + "&sOrderID=" +OrderID+ "&sState=" + State,"",feature)

       }
    }
    
    String.prototype.startsWith = function(str)
    {return (this.match("^"+str)==str)}
    </script>

</asp:Content>
